//
//  CreateMyTripCtr.m
//  Traveling
//
//  Created by 曹秀云 on 15/6/13.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "CreateMyTripCtr.h"

@interface CreateMyTripCtr ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (weak, nonatomic) IBOutlet UIView *timeView;
@property (weak, nonatomic) IBOutlet UIView *startView;
@property (weak, nonatomic) IBOutlet UIView *monthView;
@property (weak, nonatomic) IBOutlet UIView *endView;

@property (weak, nonatomic) IBOutlet UILabel *startLabel;
@property (weak, nonatomic) IBOutlet UILabel *monthLabel;
@property (weak, nonatomic) IBOutlet UILabel *endLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIPickerView *dataPickView;
@property (nonatomic , strong) NSArray *dataData;

@end
/**
 *  自建行程第一步
 */
@implementation CreateMyTripCtr

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"自建行程"];
    
   }

-(NSArray *)dataData{
    if (_dataData == nil) {
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"foods" ofType:@"plist"];
        _dataData = [NSArray arrayWithContentsOfFile:filePath];
    }
    
    return _dataData;
}

#pragma mark -PickerView的数据源

// returns the number of 'columns' to display.
#pragma mark pickerView的组数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    
    return self.dataData.count;
}

#pragma mark pickerView每一组的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    NSArray *items = self.dataData[component];
    return items.count;
}

#pragma mark -PickerView的代理

#pragma mark 每一组每一行显示文字
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    //1.获取对应组的数据
    NSArray *items = self.dataData[component];
    return items[row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"第几组： %ld 第几行 %ld",(long)component,(long)row);
    //更新label的数据
    //1.获取对应列(组)的数据
    NSArray *items = self.dataData[component];
    if (component == 0) {
        //NSArray *items = self.foodsData[component];
        self.startLabel.text = items[row];
    }else if (component ==1){
        self.monthLabel.text = items[row];
    }else{
        self.endLabel.text = items[row];
    }
}


@end
